﻿// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="TestSubtractFactorDenseVectorFactor.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>
//     Exul
// </author>
// -------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.Mathematics.LinearAlgebra.Sequential.Tests.DenseVectorTest.DoubleExtensions
{
    #region Usings

    using System;

    using ExulLibrary.Mathematics.LinearAlgebra.Sequential.DoubleExtensions;

    using NUnit.Framework;

    #endregion

    /// <summary>
    ///     Test suite for <see cref="DenseVectorExtensions.Subtract(DenseVector{double},double,DenseVector{double},double)"/>.
    /// </summary>
    [TestFixture]
    [Category("ExulLibrary.Mathematics.LinearAlgebra.Sequential.DoubleExtensions.DenseVectorExtensions")]
    public sealed class TestSubtractFactorDenseVectorFactor
    {
        /// <summary>
        ///     Tests the method when subtrahend vector that has the same length as minuend vector.
        /// </summary>
        [Test]
        public void WhenMinuendAndSubtrahendHaveTheSameLength()
        {
            // Arrange
            var minuend = new DenseVector<double>(new double[] { 10, 100, 1000 });
            var subtrahend = new DenseVector<double>(new double[] { 1, 2, 3 });

            // Act
            minuend.Subtract(20, subtrahend, 10);

            // Assert
            Assert.That(minuend.Values, Is.EquivalentTo(new double[] { 190, 1980, 19970 }));
        }

        /// <summary>
        ///     Tests the method when subtrahend vector that has greater length than minuend vector.
        /// </summary>
        [Test]
        public void WhenSubtrahendHasGreaterLengthThanMinuend()
        {
            // Arrange
            var minuend = new DenseVector<double>(new double[] { 10, 100, 1000 });
            var subtrahend = new DenseVector<double>(new double[] { 1, 2, 3, 4 });

            // Act
            minuend.Subtract(20, subtrahend, 10);

            // Assert
            Assert.That(minuend.Values, Is.EquivalentTo(new double[] { 190, 1980, 19970 }));
        }

        /// <summary>
        ///     Tests the method when subtrahend vector that has less length than minuend vector.
        /// </summary>
        [Test]
        public void WhenSubtrahendHasLessLengthThanMinuend()
        {
            // Arrange
            var minuend = new DenseVector<double>(new double[] { 10, 100, 1000 });
            var subtrahend = new DenseVector<double>(new double[] { 1, 2 });

            // Act
            minuend.Subtract(20, subtrahend, 10);

            // Assert
            Assert.That(minuend.Values, Is.EquivalentTo(new double[] { 190, 1980, 1000 }));
        }

#if SAFE

        /// <summary>
        ///     Tests the method when minuend parameter is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenMinuendIsNull()
        {
            // Arrange
            var subtrahend = new DenseVector<double>(3);

            // Act and Assert
            Assert.That(
                () => DenseVectorExtensions.Subtract(null, 20, subtrahend, 10),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("minuend"));
        }

        /// <summary>
        ///     Tests the method when subtrahend parameter is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenSubtrahendIsNull()
        {
            // Arrange
            var minuend = new DenseVector<double>(3);

            // Act and Assert
            Assert.That(
                () => minuend.Subtract(20, null, 10),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("subtrahend"));
        }

#endif
    }
}